Skip to content

Major rework of KLTrialFactory and internal trial handling#37

Merged
a-hurst merged 24 commits intotestingfrom
trial_structure_redux
Feb 3, 2026
Merged

Major rework of KLTrialFactory and internal trial handling#37
a-hurst merged 24 commits intotestingfrom
trial_structure_redux

Conversation

@a-hurst
Copy link
Owner

@a-hurst a-hurst commented Feb 1, 2026

PR Description

This PR is a major overhaul of how klibs handles trials and trial generation internally, making it much easier to generate custom blocks of trials and improving the public API while largely preserving backwards compatibility. These changes also do most of the groundwork needed to add an official custom block/session structure API.

On an internal level, a big change is that the BlockIterator and TrialIterator classes are now gone and have been replaced with the new TrialSet class, which is fully documented and intended for public use. Previously, the TrialIterator class was responsible for recycling trials during the experiment runtime, which was a bit confusing and messy. The trial recycling code has now been rewritten and moved into the Experiment class itself, making things much simpler and allowing the TrialSet class (a drop-in replacement for TrialIterator) to simply be a container.

TrialSet also allows for the specification of block labels, which are used to fill self.block_label attribute during a block. This is intended to make it easier to write conditional logic for tasks with different phases or types of blocks.

This PR also does a lot of work to simplify the TrialFactory class and remove it from the public API, making its most common uses available through the Experiment class. This includes moving the loading of experiment factors into Experiment.__init__() and making the factors accessible directly through self.exp_factors within the runtime (previously required self.trial_factory.exp_factors). Additionally, the TrialFactory.dump() method has been deprecated and replaced by Experiment.generate_trials_txt(), which has also been heavily rewritten for better readability and usefulness. The class itself and its basic design are still useful internally (I tried moving more of it to the Experiment class but it wasn't as clean), it's just something I don't think end users should ever have to think about.

Also, this PR adds a bunch of unit test coverage for generating trials within the experiment runtime.

Merge Checklist

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in CHANGELOG.rst

@a-hurst a-hurst merged commit 54835fa into testing Feb 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant